/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.table.render;

import com.rw.table.TableInfo;
import com.rw.table.formatter.ICellFormatter;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;

/**
 *
 * @author Rene Tapia
 */
public class LabelCellRenderer extends ACellRenderer {

    private JLabel label;

    public LabelCellRenderer() {
        this.label = new JLabel();
        this.label.setOpaque(true);
    }

    @Override
    public Component getComponent(TableInfo info) {
        Object value = info.getValue();
        ICellFormatter formatter = info.getFormatter();
        
        String strValue = value != null ? formatter.format(value) : "";
        this.label.setText(strValue);

        int align = formatter.getAlign();
        this.label.setHorizontalAlignment(align);

        Color color = getColor(info);
        this.label.setBackground(color);

        return label;
    }

    @Override
    public boolean isEditableByClick() {
        return false;
    }
}
